package com.inossem.warehousestorage_inossem.utils;

import android.content.Context;
import android.text.TextUtils;

import com.inossem.utils.base.GsonUtils;
import com.inossem.utils.io.IOUtils;
import com.inossem.warehousestorage_inossem.bean.up_frame.UpFrameOverviewBean;

/**
 * Created by leij on 2017/6/13.
 */

public class SPUtils {

    private static final String DEFAULT_DOMAIN = "61.134.122.146";

    private static final String DEFAULT_PORT = "80";

    private static final String SP_RETAIN = "Retain"; //保存数据

    private static final String SP_SYSTEM = "System";//系统信息

    private static final String SP_WAREHOUSESTORAGE = "WarehouseStorage";//业务信息

    private static final String KEY_DOMAIN = "Domain";//域名

    private static final String KEY_PORT = "Port";//端口

    private static final String KEY_TOKEN = "Token";//Token

    private static final String KEY_NAME = "Name";//用户姓名

    private static final String KEY_LOGIN_FLAG = "Login_Flag";//登录状态

    private static final String KEY_RECEIVE_INFORMATION = "Receive_Information";//验收

    private static final String KEY_RECEIVE_INSTORAGE_INFORMATION = "Receive_In_Storage_Information";//验收入库

    private static final String KEY_FREE_INSTORAGE_INFORMATION = "Free_In_Storage_Information";//免检入库

    private static final String KEY_OTHER_INSTORAGE_INFORMATION = "Other_In_Storage_Information";//其他入库

    private static final String KEY_TENDER_INSTORAGE_INFORMATION = "Tender_In_Storage_Information";//招采入库

    private static final String KEY_PICKING_OUTSTORAGE_INFORMATION = "Picking_Out_Storage_Information";//领料出库

    private static final String KEY_SALE_OUTSTORAGE_INFORMATION = "Sale_Out_Storage_Information";//销售出库

    private static final String KEY_RETURN_OUTSTORAGE_INFORMATION = "Return_Out_Storage_Information";//采购退货

    public static final String KEY_UP_FRAME_INFORMATION = "Up_Frame_Information"; //上架

    public static final String KEY_STORAGE_MGR_MATR_INFORMATION = "Storage_Mgr_Information";

    public static final String KEY_INVENTORY_INFORMATION = "Inventory_Information";

    public static final String KEY_CHANGE_STORAGE_INFORMATION = "Change_Storage_Information"; //转储管理

    public static final String KEY_REFUND_STORAGE_INFORMATION = "Refund_Storage_Information"; //退货管理

    public static final void clearSystem(Context context) {
        IOUtils.clear(context, SP_SYSTEM);
    }

    public static final void clearWarehouseStorage(Context context) {
        IOUtils.clear(context, SP_WAREHOUSESTORAGE);
    }

    public static String getDomain(Context context) {
        return IOUtils.getString(context, SP_RETAIN, KEY_DOMAIN, DEFAULT_DOMAIN);
    }

    public static void saveDomain(Context context, String domain) {
        IOUtils.putString(context, SP_RETAIN, KEY_DOMAIN, domain);
    }

    public static String getPort(Context context) {
        return IOUtils.getString(context, SP_RETAIN, KEY_PORT, DEFAULT_PORT);
    }

    public static void savePort(Context context, String port) {
        IOUtils.putString(context, SP_RETAIN, KEY_PORT, port);
    }

    public static String getToken(Context context) {
        return IOUtils.getString(context, SP_SYSTEM, KEY_TOKEN, "");
    }

    public static void saveToken(Context context, String token) {
        IOUtils.putString(context, SP_SYSTEM, KEY_TOKEN, token);
    }

    public static void removeToken(Context context) {
        IOUtils.remove(context, SP_SYSTEM, KEY_TOKEN);
    }

    public static String getName(Context context) {
        return IOUtils.getString(context, SP_SYSTEM, KEY_NAME, "");
    }

    public static void saveName(Context context, String name) {
        IOUtils.putString(context, SP_SYSTEM, KEY_NAME, name);
    }

    public static void removeName(Context context) {
        IOUtils.remove(context, SP_SYSTEM, KEY_NAME);
    }

    public static boolean getLoginFlag(Context context) {
        return IOUtils.getBoolean(context, SP_SYSTEM, KEY_LOGIN_FLAG, false);
    }

    public static void saveLoginFlag(Context context, boolean loginFlag) {
        IOUtils.putBoolean(context, SP_SYSTEM, KEY_LOGIN_FLAG, loginFlag);
    }

    public static void removeLoginFlag(Context context) {
        IOUtils.remove(context, SP_SYSTEM, KEY_LOGIN_FLAG);
    }

    public static String getReceiveInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INFORMATION, "");
    }

    public static void saveReceiveInformation(Context context, String receiveInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INFORMATION, receiveInformation);
    }

    public static void removeReceiveInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INFORMATION);
    }

    public static String getReceiveInStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INSTORAGE_INFORMATION, "");
    }

    public static void saveReceiveInStorageInformation(Context context, String receiveInStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INSTORAGE_INFORMATION, receiveInStorageInformation);
    }

    public static void removeReceiveInStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_RECEIVE_INSTORAGE_INFORMATION);
    }

    public static String getFreeInStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_FREE_INSTORAGE_INFORMATION, "");
    }

    public static void saveFreeInStorageInformation(Context context, String freeInStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_FREE_INSTORAGE_INFORMATION, freeInStorageInformation);
    }

    public static void removeFreeInStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_FREE_INSTORAGE_INFORMATION);
    }

    public static String getOtherInStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_OTHER_INSTORAGE_INFORMATION, "");
    }

    public static void saveOtherInStorageInformation(Context context, String otherInStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_OTHER_INSTORAGE_INFORMATION, otherInStorageInformation);
    }

    public static void removeOtherInStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_OTHER_INSTORAGE_INFORMATION);
    }

    public static String getTenderInStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_TENDER_INSTORAGE_INFORMATION, "");
    }

    public static void saveTenderInStorageInformation(Context context, String tenderInStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_TENDER_INSTORAGE_INFORMATION, tenderInStorageInformation);
    }

    public static void removeTenderInStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_TENDER_INSTORAGE_INFORMATION);
    }

    public static String getPickingOutStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_PICKING_OUTSTORAGE_INFORMATION, "");
    }

    public static void savePickingOutStorageInformation(Context context, String pickingOutStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_PICKING_OUTSTORAGE_INFORMATION, pickingOutStorageInformation);
    }

    public static void removePickingOutStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_PICKING_OUTSTORAGE_INFORMATION);
    }

    public static String getSaleOutStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_SALE_OUTSTORAGE_INFORMATION, "");
    }

    public static void saveSaleOutStorageInformation(Context context, String saleOutStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_SALE_OUTSTORAGE_INFORMATION, saleOutStorageInformation);
    }

    public static void removeSaleOutStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_SALE_OUTSTORAGE_INFORMATION);
    }

    public static String getReturnOutStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_RETURN_OUTSTORAGE_INFORMATION, "");
    }

    public static void saveReturnOutStorageInformation(Context context, String returnOutStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_RETURN_OUTSTORAGE_INFORMATION, returnOutStorageInformation);
    }

    public static void removeReturnOutStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_RETURN_OUTSTORAGE_INFORMATION);
    }

    public static String getChangeStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_CHANGE_STORAGE_INFORMATION, "");
    }

    public static void saveChangeStorageInformation(Context context, String changeStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_CHANGE_STORAGE_INFORMATION, changeStorageInformation);
    }

    public static void removeChangeStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_CHANGE_STORAGE_INFORMATION);
    }

    public static String getRefundStorageInformation(Context context) {
        return IOUtils.getString(context, SP_WAREHOUSESTORAGE, KEY_REFUND_STORAGE_INFORMATION, "");
    }

    public static void saveRefundStorageInformation(Context context, String refundStorageInformation) {
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, KEY_REFUND_STORAGE_INFORMATION, refundStorageInformation);
    }

    public static void removeRefundStorageInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_REFUND_STORAGE_INFORMATION);
    }

    public static UpFrameOverviewBean getUpFrameInformation(Context context) {
        return getInformation(context, UpFrameOverviewBean.class, KEY_UP_FRAME_INFORMATION);
    }

    public static void saveUpFrameInformation(Context context, UpFrameOverviewBean bean) {
        saveInformation(context, KEY_UP_FRAME_INFORMATION, bean);
    }

    public static void removeUpFrameInformation(Context context) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, KEY_UP_FRAME_INFORMATION);
    }

    public static <T> T getInformation(Context context, Class<T> cla, String key) {
        String s = IOUtils.getString(context, SP_WAREHOUSESTORAGE, key, null);
        if (TextUtils.isEmpty(s)) {
            return null;
        } else {
            return GsonUtils.fromJson(s, cla);
        }

    }

    public static void saveInformation(Context context, String key, Object bean) {
        String json = GsonUtils.toJson(bean);
        IOUtils.putString(context, SP_WAREHOUSESTORAGE, key, json);
    }

    public static void removeInformation(Context context, String key) {
        IOUtils.remove(context, SP_WAREHOUSESTORAGE, key);
    }
}
